<template>
	<div id="index">
		<div class="i_maxW">
			<div class="userP">
				<div class="user_img box">
					<span>
						<img :src="BASE_URL + $store.getters.userInfo.avatar_path">
					</span>
					<div class="user_name box">
						<h3>{{$store.getters.userInfo.name}}</h3>
						<!-- <div>用户名: {{$store.getters.userInfo.number}}</div> -->
					</div>
				</div>
				<div class="user_if box">
					<span><i class="ipm but_Collection01_up"></i>关注 {{followNumber ? followNumber : 0}}</span>
					<span><i class="ipm icon_fensi"></i>粉丝 {{fansNumber ? fansNumber : 0}}</span>
					<el-button type="primary" @click="spaceURL()">个人主页</el-button>
				</div>
			</div>
			<!--  -->
			<div class="user_px">
				<i class="ipm slogn01"></i>
			</div>
			<!--  -->
			<div class="u_content">
				<div class="content_l box">
					<div class="content_l1">
						<div class="U_child" v-if='roleBaseid(5)'>
							<template v-if="switch_.length > 0">
								<el-select filterable v-model="switch_value" @change="changUser($event)" placeholder="切换">
									<el-option v-for="item in switch_" :key="item.id" :label="item.name" :value="item.id">
									</el-option>
								</el-select>
							</template>
							<el-tooltip class="item" effect="dark" content="绑定子女账号" placement="top">
								<i class="el-icon-circle-plus-outline" @click="showAccount"></i>
							</el-tooltip>
						</div>
						<div class="U_keyword">
							<span v-if="userLabel.role_name">{{userLabel.role_name}}</span>
							<span v-if="userLabel.sub_name &&  userLabel.sub_name != '暂未绑定科目' ">{{userLabel.sub_name}}</span>
							<template v-if='!$store.state.isSchool'>
								<span v-for="item of classUserid" :key="item.id">{{item.rename}}</span>
							</template>
						</div>
						<div class="u_info clear" v-once>
							<span @click="checkHasMsg('message')" v-if='messageName'>
								<el-badge class="box">
									<i class="ipm shouye_sixin"></i>
									<p>消息</p>
								</el-badge>
							</span>
							<template v-if='$store.state.isSchool'>
								<span @click="checkHasMsg('teach')">
									<el-badge class="box">
										<i class="ipm shouye_jiaoxuezhongxin"></i>
										<p>教学中心</p>
									</el-badge>
								</span>
							</template>
							<template v-else>
								<span @click="checkHasMsg('learn')" v-if='roleBaseid(4)'>
									<el-badge class="box">
										<i class="ipm shouye_jiaoxuezhongxin"></i>
										<p>学习中心</p>
									</el-badge>
								</span>
								<span @click="checkHasMsg('teach')"  v-if='roleBaseid(6)'>
									<el-badge class="box">
										<i class="ipm shouye_jiaoxuezhongxin"></i>
										<p>教学中心</p>
									</el-badge>
								</span>
								<span @click="checkHasMsg('class')" v-if='roleBaseid(4,6)' >
									<el-badge class="box">
										<i class="ipm shouye_wodebanji"></i>
										<p>我的班级</p>
									</el-badge>
								</span>
								<template  v-if='roleBaseid(5)'>
									<span @click="checkHasMsg('grade')">
										<el-badge class="box">
											<i class="child_1"></i>
											<p>孩子成长</p>
										</el-badge>
									</span>
									<span @click="checkHasMsg('homework')">
										<el-badge class="box">
											<i class="child_2"></i>
											<p>孩子作业</p>
										</el-badge>
									</span>
								</template>
							</template>
						</div>
					</div>
					<!-- 通讯录 -->
					<div class="content_l2" v-if="showContact">
						<div class="u_mail clear">
							<span>通讯录</span>
							<router-link to="/personal/contact/mailList">查看<i>></i></router-link>
						</div>
						<div class="u_mail2 ">
							<i class="ipm shouye_tongxunlu"></i>
							<span>
								<i>私信</i>
								<strong v-if="numberContact >= 1">{{numberContact}}</strong>
								<em v-else>0</em>
							</span>
						</div>
					</div>
					<!-- 个人资源 -->
					<template v-if='!$store.state.isSchool'>
						<div class="content_l2" v-if="showResource ">
							<div class="u_mail clear">
								<span>个人资源</span>
								<router-link to="/personal/resource/index">查看<i>></i></router-link>
							</div>
							<div class="u_mail2">
								<i class="ipm shouye_ziyuan"></i>
								<span>
									<i>目前资源数</i>
									<strong v-if="numberResource >= 1">{{numberResource}}</strong>
									<em v-else>0</em>
								</span>
							</div>
						</div>
					</template>
					<!-- 日记 -->
					<div class="content_l2" v-if="showJournal">
						<div class="u_mail clear">
							<span>日记</span>
							<router-link to="/personal/journal/index">查看<i>></i></router-link>
							<router-link to="/personal/journal/add">写一篇</router-link>
						</div>
						<div class="u_mail2">
							<i class="ipm shouye_rizhi"></i>
							<span>
								<i>当前日记</i>
								<strong v-if="numberJournal >= 1">{{numberJournal}}</strong>
								<em v-else>0</em>
							</span>
						</div>
					</div>
				</div>
				<div class="content_r box">
					<div class="myapp">
						<div class="titleH clear">
							<span>我的应用</span>
							<em @click="viewsApp" v-if="showApp">编辑应用</em>
						</div>
						<template v-if="showApp">
							<div class="myapp_icon" v-if="myapp_list != 0">
								<template v-for="(item, index) of myapp_list">
									<a @click="checkLook(item.name)" :key="item.id" class="fade-app">
										<img :src="BASE_URL+item.logo_path">
										<p>{{item.name}}</p>
									</a>
								</template>
							</div>
						</template>
						<div class="dependent" v-if="placeholder">
							<i class="ipm image_nofound"></i>
							<p>还没发现任何相关的内容哦~</p>
						</div>
					</div>
					<div class="capacity" v-if="0">
						<p>个人中心容量大小： <span><i>200m</i>/500g</span></p>
						<el-progress :text-inside="true" :stroke-width="15" :percentage="70"></el-progress>
					</div>
				</div>
			</div>
		</div>
		<!--  -->
		<el-dialog title="应用管理" :visible.sync="appAdministration" width="800px" :close-on-click-modal="false">
			<div class="Administration">
				<el-tabs v-model=" activeName">
					<el-tab-pane v-for="(type_id, index) of ApptypeList" :label="type_id.name" :name="type_id.id.toString()" :key="index">
						<template>
							<div class="Administration_title">已添加</div>
							<ul class="clear" v-if="new_myapp_list.length != 0">
								<template v-for="(item, index) of new_myapp_list">
									<template v-if="activeName == 0">
										<li class="Administration_ls" :key="item.id">
											<div class="Administration_ls_icn">
												<img :src="BASE_URL + item.logo_path" :alt="item.name">
												<div>
													<i class="el-icon-delete" @click="removeApp(index, item)"></i>
													<span>移除</span>
												</div>
											</div>
											<p>{{item.name}}</p>
										</li>
									</template>
									<template v-else>
										<li class="Administration_ls" :key="item.id" v-if="item.app_type_id == type_id.id">
											<div class="Administration_ls_icn">
												<img :src="BASE_URL + item.logo_path" :alt="item.name">
												<div>
													<i class="el-icon-delete" @click="removeApp(index, item)"></i>
													<span>移除</span>
												</div>
											</div>
											<p>{{item.name}}</p>
										</li>
									</template>
								</template>
							</ul>
							<div class="dependent" v-if="new_myapp_list.length == 0 && activeName == 0">
								<p>还没发现任何相关的内容哦~</p>
							</div>
						</template>
						<div class="Administration_title">未添加</div>
						<ul class="clear" v-if="userAppList.length != 0">
							<template v-for="(item, index) of not_myapp_list">
								<template v-if="activeName == 0">
									<li class="Administration_ls" :key="item.id">
										<div class="Administration_ls_icn">
											<img :src="BASE_URL + item.logo_path" :alt="item.name">
											<div>
												<i class="el-icon-circle-plus-outline" @click="addAppList(index, item)"></i>
												<span>添加</span>
											</div>
										</div>
										<p>{{item.name}}</p>
									</li>
								</template>
								<template v-else>
									<li class="Administration_ls" v-if="item.app_type_id == type_id.id" :key="item.id">
										<div class="Administration_ls_icn">
											<img :src="BASE_URL + item.logo_path" :alt="item.name">
											<div>
												<i class="el-icon-circle-plus-outline" @click="addAppList(index, item)"></i>
												<span>添加</span>
											</div>
										</div>
										<p>{{item.name}}</p>
									</li>
								</template>
							</template>
						</ul>
						<div class="dependent" v-if="not_myapp_list.length == 0">
							<p>还没发现任何相关的内容哦~</p>
						</div>
					</el-tab-pane>
				</el-tabs>
				<div class="buttonCSS">
					<el-button type="primary" plain @click="cancelViews">取消</el-button>
					<el-button type="primary" @click="submitApp()">确定</el-button>
				</div>
			</div>
		</el-dialog>
		<el-dialog title="绑定账号" :visible.sync="accountvisible" width="400px" :close-on-click-modal="false">
			<div class="account-form">
				<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
					<el-form-item label="账号" prop="name">
						<el-input v-model="ruleForm.name" placeholder='请输入4~16位账号'></el-input>
					</el-form-item>
					<el-form-item label="密码" prop="password">
						<el-input v-model="ruleForm.password" type='password' placeholder='请输入6~20位密码'></el-input>
					</el-form-item>
					<el-form-item class="buttonCSS" label-width="0">
						<el-button @click="resetForm('ruleForm')" plain type="primary">取消</el-button>
						<el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-dialog>
	</div>
</template>
<script>
export default {
	name: '',
	data() {
		return {
			accountvisible: false,
			ruleForm: {
				name: "",
				password: ''
			},
			rules: {
				name: [
					{ pattern: this.rules.account.reg, message: this.rules.account.msg, trigger: 'blur' },
					{ validator: this.validateAccounts, trigger: 'blur', required: true }
				],
				password: [
					{ required: true, pattern: this.rules.pwd.reg, message: this.rules.pwd.msg, trigger: 'blur' }
				],
			},
			labelParam: {
				id: this.$store.getters.userInfo.id,
				userid: this.$g.user_id
			},
			infoParam: {
				id: this.$store.getters.userInfo.id
			},

			userLabel: [],
			/*用户标签*/
			menuNavRouteData: deep_clone(this.$store.getters.leftMenuNav),
			/*路由*/
			authColumn: [],
			/*通讯录， 个人资源， 日记权限*/
			showContact: false,
			/*通讯录权限*/
			showResource: false,
			/*个人资源权限*/
			showJournal: false,
			/*日记权限*/
			showApp: false,
			/*我的应用权限*/

			numberContact: 0,
			/*私信的数量*/
			numberResource: 0,
			/*资源的数量*/
			numberJournal: 0,
			/*日记的数量*/
			followNumber: 0,
			/*关注的数据*/
			fansNumber: 0,
			/*粉丝的数据*/

			switch_value: this.$g.user_id,
			/*小孩身份id*/
			switch_: [],
			/*小孩身份l列表*/


			selectNav: JSON.parse(sessionStorage.getItem("route_str")),

			module: {
				msg: '',
				class: '',
				teach: '',
				learn: '',
				grade: '',
				task: '',
			},

			appAdministration: false,
			/*关闭应用权限*/
			activeName: '0',
			ApptypeList: [],
			userAppList: [],
			app_id: 0,
			myapp_list: [], //app列表
			new_myapp_list: [], //重新添加的app
			not_myapp_list: [],
			placeholder: true,
			myapp_id: [], // 提交app的id
			existLsist: [], //已经添加的app
			loading: true,
			classUserid: [],
			/*班级列表*/

			nameArr: ['班级圈', '班级通知', '班级资源', '班级成员', '班级课表', '学生成绩', '请假', '学生档案', '班级任务'],
			routerArr: [],
			/*角色权限*/
		}
	},
	watch: {

	},
	created() {
		this.getmyapp_list()
		this.checkAuth();
		this.getSwitch()
		this.follow()
		this.fans()
		this.getUserLabel();
		this.getClassUserid()
	
	},
	computed: {
		messageName(){
			let selectNav = deep_clone(  this.$router.options.routes[1].children )
			let msg = selectNav.filter(item=>item.path === "message")
			return msg.length > 0 ? true : false
		}
	},
	mounted() {

	},
	methods: {
		/**
		 * 绑定子女账号
		 * @DateTime 2020-09-17T10:04:33+0800
		 * @qiu_m
		 * @return   {[type]}                 [description]
		 */
		showAccount() {
			this.accountvisible = true
			this.$refs.ruleForm && this.$refs.ruleForm.resetFields();
		},
		validateAccounts(rule, value, callback) {
			if (value === '') {
				return callback(new Error('请输入登录账号'));
			} else if (!this.validateName(value)) {
				return callback(new Error('不能输入空格符号'));
			} else {
				callback()
			}
		},
		validateName(name) {
			if (name === null || name === undefined) return false

			let appell = /^[\S]{1,}$/

			return name.toString().match(appell)
		},
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {

					let success = (res => {
						this.accountvisible = false

						let data = res.data
						this.childrenNumber(data.id)
						this.getClassUserid()

					})
					let fail = (res => {
						this.$message.error(res.msg)
					})
					let params = {
						number: this.ruleForm.name,
						password: this.ruleForm.password
					}

					this.$ajax.get('api/user/check_user', { params, func: { success: success, fail: fail } })
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		childrenNumber(id) {
			let success = (res => {
				this.$message.success(res.msg)
				this.switch_value = this.$g.user_id
				this.getSwitch()
				this.$router.go(0)
			})
			let data = {
				follow_id: id,
				user_id: this.$g.user_id,
				add_delete: 'add',
				type: 1
			}
			this.$ajax.post('api/user/bind_relation', data, { func: { success: success } })
		},
		resetForm(formName) {
			this.accountvisible = false
			this.$refs[formName].resetFields();
		},
		/*
			获取用户所在的班级
		*/
		getClassUserid() {
			let success = (res => {
				this.classUserid = res.data
			});

			let params = {user_id: this.$g.user_id}
			this.$ajax.get('api/org/class_userid', { params, func: { success: success} })

		},
		// 应用跳转
		routerUrl(url) {
			let host = sessionStorage.getItem('host')
			let redirectParams = sessionStorage.getItem('redirect_params')
			let link = `${this.BASE_URL}${redirectParams}&host=${host}&routerUrl=${url}`
			window.open(link)

		},
		/**
		 * 应用查看 & 跳转
		 * @DateTime 2020-03-05T14:39:12+0800
		 * @param    {[type]}                 name [description]
		 * @return   {[type]}                      [description]
		 */
		checkLook(name) {
			let BASE_URL = sessionStorage.getItem('host_addr')
			let CheckSchoolAppCode =  sessionStorage.getItem( 'CheckSchoolAppCode' )
			let AppCode = null
			if (CheckSchoolAppCode != '') {
				AppCode = `&CheckSchoolAppCode=${CheckSchoolAppCode}`
			}
			switch (name) {
				case '通讯录':
					this.$router.push('/personal/contact/mailList');
					break;
				case '班级圈':
					if (this.classUserid.length == 0) {
						return this.$message.warning("请联系管理员绑定班级")
					}
					this.$router.push('/class/circle/index');
					break;
				case '学生成绩':
					if (this.classUserid.length == 0) {
						return this.$message.warning("请联系管理员绑定班级")
					}
					this.$router.push('/class/achieve/list');
					break;
				case '班级课表':
					if (this.classUserid.length == 0) {
						return this.$message.warning("请联系管理员绑定班级")
					}
					this.$router.push('/class/schedule/index');
					break;
				case '收藏':
					this.$router.push('/collect/openclass/index');
					break;
				case '学习足迹':
					this.$router.push('/learn/history/book');
					break;
				case '学习笔记':
					this.$router.push('/learn/note/index');
					break;
				case '教学直播':
					this.$router.push('/teach/live/listlive');
					break;
				case '我的提问':
					this.$router.push('/learn/ask/index');
					break;
				case '我的回答':
					this.$router.push('/teach/ask/index');
					break;
				case '请假':
					if (this.classUserid.length == 0) {
						return this.$message.warning("请联系管理员绑定班级")
					}
					this.$router.push('/class/leave/index');
					break;
				case '直播预约':
					this.$router.push('/teach/live/listappoint');
					break;
				case '班级通知':
					if (this.classUserid.length == 0) {
						return this.$message.warning("请联系管理员绑定班级")
					}
					this.$router.push('/class/notice/index');
					break;
				case '学籍档案':
					this.routerUrl('schoolroll'+AppCode)
					break;

				case '错题本':
					this.routerUrl('exercises'+AppCode)
					break;
				case '公开课':
					this.routerUrl('/home/openclassList')
					break;
				case '优课专辑':
					this.routerUrl('/home/albumList')
					break;
				case '名师中心':
					this.routerUrl('teach'+AppCode)
					break;
				case '备忘录':
					this.routerUrl('memorandum'+AppCode)
					break;
				case '日程协同':
					this.routerUrl('calendar'+AppCode)
					break;
				case '评课排课':
					this.routerUrl('course'+AppCode)
					break;
				case '教师培训':
					this.routerUrl('train'+AppCode)
					break;
				case '学科圈组':
					this.routerUrl('group'+AppCode)
					break;
				case '教学AI':
					this.routerUrl('analysis'+AppCode)
					break;
				case '校园巡检':
					this.routerUrl('inspection'+AppCode)
					break;
				case '大数据':
					this.routerUrl('bigdata'+AppCode)
					break;
				case '协同备课':
					this.routerUrl('prepare'+AppCode)
					break;
				case '网络教研':
					this.routerUrl('netteach'+AppCode)
					break;
				case '智慧组卷':
					this.routerUrl('test'+AppCode)
					break;
				case '直播':
					this.routerUrl('/home/liveList')
					break;
				case '教学资源':
					this.routerUrl('/home/resourceList')
					break;
				case '电子邮箱':
					this.routerUrl('/email/inbox'+AppCode)
					break;
				case '校友服务':
					this.routerUrl('alumni'+AppCode)
					break;
				case '资产管理':
					this.routerUrl('assetManage'+AppCode)
					break;
				case '住宿管理':
					this.routerUrl('dormitory'+AppCode)
					break;
				case '学籍管理':
					this.routerUrl('schoolroll'+AppCode)
					break;
				case '审批':
					this.routerUrl('examine'+AppCode)
					break;
				case '智慧练习':
					this.routerUrl('exercises'+AppCode)
					break;
				case '车辆管理':
					this.routerUrl('vehicle'+AppCode)
					break;
				case '食堂菜单':
					this.routerUrl('canteen'+AppCode)
					break;
				case '活动赛事':
					this.routerUrl('events'+AppCode)
					break;
				case '用车管理':
					this.routerUrl('vehicle'+AppCode)
					break;
				case '宿舍管理':
					this.routerUrl('dormitory'+AppCode)
					break;
					// case '校园广播':
					// window.open(BASE_URL +':8083' + redirect_params+'/course');
					// break;

			}
		},
		/**
		 * 跳转到个人中心
		 * @DateTime 2020-03-05T14:30:53+0800
		 * @return   {[type]}                 [description]
		 */
		spaceURL() {
			let host = sessionStorage.getItem('host')
			let redirectParams = sessionStorage.getItem('redirect_params')
			let url = `${this.BASE_URL}${redirectParams}&host=${host}&routerUrl=space/video&id=${this.$g.user_id}`
			window.open(url)
		},
		/**
		 * 关闭应用管理
		 * @DateTime 2020-03-05T14:31:21+0800
		 * @return   {[type]}                 [description]
		 */
		cancelViews() {
			this.new_myapp_list = []
			this.myapp_id = []
			this.appAdministration = false
		},
		/**
		 * 删除应用管理的应用
		 * @DateTime 2020-03-05T14:31:40+0800
		 * @param    {[type]}                 index [description]
		 * @param    {[type]}                 item  [description]
		 * @return   {[type]}                       [description]
		 */
		removeApp(index, item) {

			this.new_myapp_list.splice(index, 1)
			this.myapp_id.splice(index, 1)
			this.not_myapp_list.push(item)
		},
		//添加 app
		addAppList(index, item) {

			this.new_myapp_list.push(item)
			this.not_myapp_list.splice(index, 1)

		},
		// 保存操作的应用
		submitApp() {

			for (var i = 0; i < this.new_myapp_list.length; i++) {
				if (this.new_myapp_list[i].id) {
					this.myapp_id.push(this.new_myapp_list[i].id)
				}

			}

			let success = (res => {
				this.ApptypeList = []
				this.$message.success(res.msg)
				this.appAdministration = false
				this.getmyapp_list()
			})

			let params = {
				app_type_id: 0,
				app_id: this.myapp_id
			}
			this.$ajax.post('api/app/user_app', params, { func: { success, success } })
		},
		/**
		 * 进行编辑应用的弹窗 数据查看
		 * @DateTime 2020-03-05T14:32:30+0800
		 * @return   {[type]}                 [description]
		 */
		viewsApp() {
			this.appAdministration = true
			this.myapp_id = []
			this.getApptype()
			this.getuserApp()
		},
		//获取我的应用列表
		getmyapp_list() {
			let success = (res => {
				this.myapp_list = res.data;
				this.loading = false
				this.placeholder = this.myapp_list.length === 0 ? true : false
				let is_bind = 1

				/*获取所有权限的name*/
				let routeStr = sessionStorage.getItem('appList') ? JSON.parse(sessionStorage.getItem('appList')) : []
				this.routerArr = routeStr.map(item => item.title)

				let myappid = [26, 28, 48]
				for (let i = this.myapp_list.length - 1; i >= 0; i--) {

					this.$set(this.myapp_list[i], 'is_bind', is_bind)

					if (myappid.includes(this.myapp_list[i].id)) {
						this.myapp_list.splice(i, 1)
					}

					if (!this.routerArr.includes(this.myapp_list[i].name)) {
						this.myapp_list.splice(i, 1)

					}
				}

			})
			let params = {}
			this.$ajax.get('api/app/myapp_list', { params, func: { success: success} })

		},
		// 获取我能操作的应用
		getuserApp() {

			let success = (res => {
				console.log(JSON.parse(JSON.stringify(res.data)), '666667')
				let data = res.data;

				let hash = {};
				let arr = data.reduceRight((item, next) => {
					hash[next.id] ? '' : hash[next.id] = true && item.push(next);
					return item
				}, [])

				this.userAppList = arr;


				/*  未添加的app */
				let myapp = []
				let noapp = []
				for (var i = 0; i < arr.length; i++) {
					if (!this.routerArr.includes(arr[i].name)) {
						arr.splice(i, 1)
					}

					arr[i].is_bind == 1 ? myapp.push(arr[i]) : noapp.push(arr[i])

				}

				this.new_myapp_list = myapp
				this.not_myapp_list = noapp

				let myappid = [26, 28, 48]
				for (let i = this.not_myapp_list.length - 1; i >= 0; i--) {

					if (myappid.includes(this.not_myapp_list[i].id)) {
						this.not_myapp_list.splice(i, 1)
					}

				}

			})

			let params = { app_type_id: this.app_id }
			this.$ajax.get('api/app/user_app', { params, func: { success: success} })

		},
		// 获取app分类导航
		getApptype() {
			let success = (res => {
				console.log(JSON.parse(JSON.stringify(res.data)), '666667')
				this.ApptypeList = res.data
			})

			let params = {}
			this.$ajax.get('api/app/apptype', { params, func: { success: success} })

		},
		changUser(parent_child_id) {
			//设置当前父母操作的学生id

			sessionStorage.setItem('parent_child_id', parent_child_id);
			var inx = getOneColumn(this.switch_, 'userid').indexOf(parent_child_id);
			var parent_child_class_id = inx > -1 ? this.switch_[inx].org_id : '';
			sessionStorage.setItem('parent_class_id', parent_child_class_id)
			sessionStorage.setItem('parent_child_class_id', parent_child_class_id)
			sessionStorage.setItem('classId', parent_child_class_id)
		},
		/**
		 * 粉丝的数据
		 * @DateTime 2020-03-05T14:33:51+0800
		 * @return   {[type]}                 [description]
		 */
		fans() {
			let success = (res => {
				let data = res.data
				this.fansNumber = data.data_sum;
			})

			let params = {
				user_id: this.$g.user_id,
				type: 0,
				data_type: 2
			}
			this.$ajax.get('api/user/relation', { params, func: { success: success} })

		},
		/**
		 * 关注的数据
		 * @DateTime 2020-03-05T14:34:13+0800
		 * @return   {[type]}                 [description]
		 */
		follow() {
			let success = (res => {
				let data = res.data
				this.followNumber = data.data_sum;
			})
			let params = {
				user_id: this.$g.user_id,
				type: 1,
				data_type: 2
			}
			this.$ajax.get('api/user/relation', { params, func: { success: success} })
		},
		/**
		 * 消息，教学中心，我的班级，入口
		 * @DateTime 2020-03-05T14:34:47+0800
		 * @param    {[type]}                 name [description]
		 * @return   {[type]}                      [description]
		 */
		checkHasMsg(name) {

			let id = sessionStorage.getItem('classId')
			let [pathName, children, children_inx, path, module, classObj] = [
				[], '', '', '', '', ''
			]

			for (let i = 0; i < this.selectNav.length; i++) {

				module = this.selectNav[i]
				path = this.selectNav[i].path
				pathName.push(this.selectNav[i].path)

				if (path === name && module.children.length !== 0) {
					children = module.children[0].path
					if (module.children[0].children.length !== 0) {
						children_inx = module.children[0].children[0].path
					}
				} else if (path === 'class') {
					classObj = this.selectNav[i]
				}


			}
			// console.log(pathName.includes(name),pathName, name);
			let moduleName = []



			/*if (pathName.includes('class') && name === 'class') {
				let url = `/class/${children}/${children_inx}`
				this.$router.push(url)
			} else if (pathName.includes('teach') && name === 'teach') {
				let url = `/teach/${children}/${children_inx}`
				this.$router.push(url)
			} else if (pathName.includes('learn') && name === 'learn') {
				let url = `/learn/${children}/${children_inx}`
				this.$router.push(url)
			} else if (pathName.includes('message') && name === 'message') {
				let url = `/message/${children}/${children_inx}`
				this.$router.push(url)
			} else*/
			if (pathName.includes('class') && name === 'grade') {

				for (let j = 0; j < classObj.children.length; j++) {
					moduleName.push(classObj.children[j].path)
				}
				
				if (moduleName.includes('achieve')) {
					let url = `/class/achieve/index?id=${id}`
					this.$router.push(url)
				} else {
					this.$message.error('请先绑定该模块,详情请联系管理员');
				}
			} else if (pathName.includes('class') && name === 'homework') {

				for (let j = 0; j < classObj.children.length; j++) {
					moduleName.push(classObj.children[j].path)
				}
		
				if (moduleName.includes('homework')) {
					let url = `/class/homework/index?id=${id}`
					this.$router.push(url)
				} else {
					this.$message.error('请先绑定该模块,详情请联系管理员');
				}
			}else if( pathName.includes(name)){
				let url = `/${name}/${children}/${children_inx}`
				this.$router.push(url)
			} else {
				this.$message.error('请先绑定该模块,详情请联系管理员');

			}

		},
		//切换小孩身份
		getSwitch() {
			let success = (res => {
				let data = res.data;
				if (data.length === 0 || data.indexOf(null) > -1) {
					return
				}
				this.switch_ = data;
				if (this.switch_.length !== 0) {
					sessionStorage.setItem('parent_class_id', data[0].id)
				}

				this.switch_value = sessionStorage.getItem('parent_child_id') ? parseInt(sessionStorage.getItem('parent_child_id')) : this.switch_[0].id;

			});

			let params = {
				user_id: this.switch_value,
				type: 3,
				data_type: 0
			}
			this.$ajax.get('api/user/relation', { params, func: { success: success} })
		},
		checkAuth() {
			if (!is_empty(this.menuNavRouteData.children)) {
				this.authColumn = getOneColumn(this.menuNavRouteData.children, 'authName');
			}

			//通讯录权限
			if (this.authColumn.includes('contact')) {
				this.showContact = true;
				this.getContactNumber();
			}
			//资源权限
			if (this.authColumn.includes('resource')) {
				this.showResource = true;
				this.getResourceNumber();
			}
			//日志权限
			if (this.authColumn.includes('journal')) {
				this.showJournal = true;
				this.getJournalNumber();
			}
			//app权限
			if (this.authColumn.includes('app')) {
				this.showApp = true;
			}
		},
		/**
		 * 私信的数量
		 * @DateTime 2020-03-05T14:35:55+0800
		 * @return   {[type]}                 [description]
		 */
		getContactNumber() {
			let success = (data => {
				this.numberContact = data.data;
			})
			let fail = (data => {})
			//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
			this.$ajax.get('api/user/chat_number', { params: {}, func: { success: success, fail: fail } })
		},
		/**
		 * 目前资源数
		 * @DateTime 2020-03-05T14:36:33+0800
		 * @return   {[type]}                 [description]
		 */
		getResourceNumber() {
			let success = (data => {
				this.numberResource = data.data.data_sum;
			})
			let fail = (data => {})

			let params = {
				create_id: this.$g.user_id,
				data_type: 2,
				not_in_file_type: 2,
				status: "1,2,3"
			}
			this.$ajax.get('api/resource/resource', { params, func: { success: success, fail: fail} })
			
		},
		/**
		 * 当前日记
		 * @DateTime 2020-03-05T14:36:45+0800
		 * @return   {[type]}                 [description]
		 */
		getJournalNumber() {
			let success = (data => {
				this.numberJournal = data.data;
			})
			let fail = (data => {})
			//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
			this.$ajax.get('api/user/journal_number', { params: {}, func: { success: success, fail: fail } })
		},
		//用户标签
		getUserLabel() {
			let success = (data => {
				this.userLabel = data.data[0];
			})
			//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
			this.$ajax.get('api/user/user', { params: this.labelParam, func: { success: success } })
		}
	}
}
</script>